import request from "@/utils/request";
import {serverIp} from "../../public/config.js";
const API_BASE_URL = `http://${serverIp}:8081/jdyfy`;

/**
 * 角色相关API
 *
 */

//角色分页查询
export const getRolePage = (pageNum, pageSize) =>{
    return request.get(`${API_BASE_URL}/rolePage`,{
        params: {
            pageNum,
            pageSize
        }
    }).then(res => {
        return res.data;
    })
};

//删除角色
export const deleteRole = (id) =>{
    return request.delete(`${API_BASE_URL}/role/del`, {data: id})
        .then(res => {
            return res;
        })
};

//新增或修改角色
export const addRole = (form) =>{
    return request.post(`${API_BASE_URL}/role/save`, form)
        .then(res => {
            return res;
        }).catch(err => {
            throw new Error('请求失败'); // 抛出请求错误
        });
};

//获取菜单
export const getMenu = () =>{
    return request.get(`${API_BASE_URL}/menu/findMenus`)
        .then(res => {
            return res;
        }).catch(err => {
            throw new Error('请求失败'); // 抛出请求错误
        });
};

//角色菜单保存
export const saveRoleMenu = (roleId,keys) =>{
    return request.post(`${API_BASE_URL}/roleMenu/`+ roleId, keys)
        .then(res => {
            return res;
        }).catch(err => {
            throw new Error('请求失败'); // 抛出请求错误
        });
};


export const getRoleMenu = (roleId) =>{
    return request.post(`${API_BASE_URL}/getRoleMenu/`+ roleId)
        .then(res => {
            return res;
        }).catch(err => {
            throw new Error('请求失败'); // 抛出请求错误
        });
};